
//-------------------------------
// TABLE A5
//-------------------------------


clear
use masterdata_policing.dta

encode state, gen(state2)
encode county, gen(county2)

gen vcrime_tot = murders + agg_assault + forc_rape + robbery
gen vcrime_clear = murders_clear + agg_assault_clear + forc_rape_clear + robbery_clear
gen vcrimeclearrate = vcrime_clear/vcrime_tot
gen pcrime_tot = burglary + larcenytheft + mvt
gen pcrime_clear = burglary_clear + larceny_clear + mvt_clear
gen pcrimeclearrate = pcrime_clear/pcrime_tot


gen youthratio = (pop15to17+pop18to24+pop25to34)/totalpopulation
gen blackratio = black/totalpopulation
gen lessthanhighratio = lessthanhigh/popover25
gen unempratio = unemployed/civilian
gen lincome = ln(medianincome)
gen lnvcrime = ln(vcrime_tot + 1)
gen lnpcrime = ln(pcrime_tot + 1)
gen lpop = ln(population)

replace vcrimeclearrate = vcrimeclearrate*100
replace pcrimeclearrate = pcrimeclearrate*100

replace policebudget = policebudget*100
replace youthratio = youthratio*100
replace blackratio = blackratio*100
replace lessthanhighratio = lessthanhighratio*100
replace unempratio = unempratio*100
replace gini = gini*100

gen polbudgetpc = totalbudget/population
gen totpolemppc =(fullswornofficer + fullcivilianemp + ptimeswornofficer + ptimecivilianemp)/population
gen swpolemppc = (fullswornofficer + ptimeswornofficer)/population
gen swfullpolemppc = fullswornofficer/population 

gen lvcrime_tot = ln(vcrime_tot +1)
gen lpcrime_tot = ln(pcrime_tot+1)
gen lvcrime_clear = ln(vcrime_clear +1)
gen lpcrime_clear = ln(pcrime_clear+1)


macro define demographic "policebudget swfullpolemppc lpop youthratio blackratio lessthanhighratio unemprati gini lincome"
macro define crimetype "murders agg_assault forc_rape robbery burglary larcenytheft mvt"

gen lncommute = ln(commutemin + 1)

* first stage 

eststo clear
eststo: quietly reg pctfinesandforfeits lncommute lvcrime_tot lpcrime_tot $demographic i.year i.state2, vce(cluster geo_fips) 
eststo: quietly reg pctfinesandforfeits lncommute lvcrime_tot lpcrime_tot $demographic i.year i.state2 if population <= 28010, vce(cluster geo_fips) 
eststo: quietly reg pctfinesandforfeits lncommute lvcrime_tot lpcrime_tot $demographic i.year i.state2 if population > 28010, vce(cluster geo_fips) 
eststo: quietly reg pctfinesandforfeits lncommute lvcrime_tot lpcrime_tot $demographic i.year i.state2, vce(cluster geo_fips) 
eststo: quietly reg pctfinesandforfeits lncommute lvcrime_tot lpcrime_tot $demographic i.year i.state2 if population <= 28010, vce(cluster geo_fips) 
eststo: quietly reg pctfinesandforfeits lncommute lvcrime_tot lpcrime_tot $demographic i.year i.state2 if population > 28010, vce(cluster geo_fips) 
esttab, star(** 0.05 *** 0.01) ar2
esttab using iv_first.tex, star(** 0.05 *** 0.01) ar2 replace

* F-statistics 

ivregress 2sls vcrimeclearrate (pctfinesandforfeits = lncommute) lvcrime_tot lpcrime_tot $demographic i.year i.county2, first vce(cluster geo_fips) 
estat endogenous 
estat firststage

ivregress 2sls vcrimeclearrate (pctfinesandforfeits = lncommute) lvcrime_tot lpcrime_tot $demographic i.year i.state2 if population <= 28010, first vce(cluster geo_fips) 
estat endogenous 
estat firststage

ivregress 2sls vcrimeclearrate (pctfinesandforfeits = lncommute) lvcrime_tot lpcrime_tot $demographic i.year i.state2 if population > 28010, first vce(cluster geo_fips) 
estat endogenous 
estat firststage

ivregress 2sls pcrimeclearrate (pctfinesandforfeits = lncommute) lvcrime_tot lpcrime_tot $demographic i.year i.state2, first vce(cluster geo_fips) 
estat endogenous 
estat firststage

ivregress 2sls pcrimeclearrate (pctfinesandforfeits = lncommute) lvcrime_tot lpcrime_tot $demographic i.year i.state2 if population <= 28010, first vce(cluster geo_fips) 
estat endogenous 
estat firststage

ivregress 2sls pcrimeclearrate (pctfinesandforfeits = lncommute) lvcrime_tot lpcrime_tot $demographic i.year i.state2 if population > 28010, first vce(cluster geo_fips) 
estat endogenous 
estat firststage




